package com.hw.protocol.tool.decode.hw;

import com.hw.protocol.tool.model.entity.hw.AbsFlowMeter;
import com.hw.protocol.tool.model.entity.hw.Dtu50;

/**
 * @author : lihy
 * @date : 2023/3/21 16:16
 * description: 流量计(5000/5100)实时数据解码器
 */
public class Dtu50Decode extends FlowMeterDecodeTemplate {

    private Dtu50 fm;

    public Dtu50Decode(AbsFlowMeter fm, byte[] data) {
        super(fm, data);
        this.fm = (Dtu50) fm;
    }

    @Override
    protected boolean dtu50() {
        return true;
    }

    @Override
    protected void setVolume() {
        if(fm.isDefaultVolume()){
            String volumeStr = dataBuf.readUnsignedIntLE() + dataBuf.readFloatLE() + "";
            fm.setVolume(Double.parseDouble(volumeStr));
        }else{
            fm.setVolume(dataBuf.readDoubleLE());
        }

    }

    @Override
    protected void setRealVolume() {
        if(fm.isDefaultVolume()){
            String volumeStr = dataBuf.readUnsignedIntLE() + dataBuf.readFloatLE() + "";
            fm.setRealVolume(Double.parseDouble(volumeStr));
        }else{
            fm.setRealVolume(dataBuf.readDoubleLE());
        }
    }

    @Override
    protected void setRatio() {
        fm.setRatio(dataBuf.readFloatLE());
    }

    @Override
    protected void setFactor() {
        fm.setFactor(dataBuf.readFloatLE());
    }

}
